<template>
    <div>
        <iview-table
                ref="table"
                :span1="14"
                :span2="10"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :defaultFilters="queryModel.defaultFilters"
                v-on="{changeTotalSize:changeTotalSize,changeSelect:changeSelect}">
        </iview-table>
        <br>
        <iview-page
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
        </iview-page>
        <Modal v-model="showModal" :closable='false' :mask-closable=true :width="300">
            <h3 slot="header" style="color:#2D8CF0">请输入折扣</h3>
            <Row>
                <Col span="20" offset="2">
                    <InputNumber style="width: 100%" :max="1" :min="0" v-model="discount"></InputNumber>
                </Col>
            </Row>
            <div slot="footer">
                <Button type="primary" @click="doAddDiscount">确认</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        components: {
            iviewTable,
            iviewPage
        },
        data () {
            return {
                discount: '0.8',
                selectRow: {},
                selectRows: [],
                display1: 'none',
                display2: '',
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/home',
                    defaultFilters: [
                    ]
                },
                dataModel: {
                    menuId: 0,
                    columns: [
                        {
                            title: '病房名称',
                            key: 'name',
                            width: 300,

                        },
                        {
                            title: '病房价格',
                            key: 'price',

                        },
                        {
                            title: '治疗时间',
                            key: 'duration',

                            render: (h, params) => {
                                let temp = params.row.duration
                                if (temp === 0) {
                                    temp = '不限时间'
                                } else {
                                    temp += '年'
                                }
                                return h('span', temp)
                            }
                        },
                        {
                            title: '操作',
                            width: 200,
                            align: 'center',
                            render: (h, params) => {
                                var vm = this
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px',
                                            display: vm.display2
                                        },
                                        on: {
                                            click: () => {
                                                vm.select(params.row)
                                            }
                                        }
                                    }, '选择'),
                                    h('Button', {
                                        props: {
                                            type: 'warning',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px',
                                            display: vm.display1
                                        },
                                        on: {
                                            click: () => {
                                                vm.addDiscount(params.row)
                                            }
                                        }
                                    }, '续费')
                                ]);
                            }
                        }
                    ],
                    order: 'id desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 10,
                    pageSizeOpts: [10, 50, 100, 500]
                },
                showModal: false
            };
        },
        methods: {
            select (row) {
                row.discount = 1
                this.$emit('selectHome', row)
            },
            addDiscount (row) {
                this.selectRow = row
                this.showModal = true
            },
            doAddDiscount () {
                this.showModal = false
                this.selectRow.isRenewal = 1
                this.selectRow.discount = this.discount
                this.$emit('selectHome', this.selectRow)
            },
            refresh () {
                this.$refs.table.refresh()
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            }
        }
    }
</script>

<style>

</style>
